package com.lianniu.web.tea.user.comment.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lianniu.web.base.BaseResult;
import com.lianniu.web.tea.user.comment.dao.TeaCommentDao;
import com.lianniu.web.tea.user.comment.model.TeaComment;
import com.lianniu.web.tea.user.comment.service.ITeaUserCommentService;
import com.lianniu.web.tea.user.eva.dao.TeaEvaDao;
import com.lianniu.web.tea.user.eva.model.TeaEva;

@Service
@Transactional
public class TeaUserCommentServiceImpl implements ITeaUserCommentService {
	
	private final static Logger logger = Logger.getLogger(TeaUserCommentServiceImpl.class);

	
	@Autowired
	private TeaCommentDao teaCommentDao;
	
	@Autowired
	private TeaEvaDao teaEvaDao;
	
	public BaseResult saveComment(TeaComment teaComment) {
		logger.info("TeaUserCommentServiceImpl saveComment start");
		teaCommentDao.insert(teaComment);
		logger.info("TeaUserCommentServiceImpl saveComment end");
		return BaseResult.success(teaComment);
	}

	
	public BaseResult getCommentListALl(String orderId,String userId) {
		logger.info("TeaUserCommentServiceImpl getCommentListALl start");
		Map<String,String> param = new HashMap<String,String>();
		param.put("orderId", orderId);
		param.put("userId", userId);
		List<TeaComment> teaComments = teaCommentDao.selectAllByOederId(param);
		for (TeaComment teaComment : teaComments) {
			String commentId = teaComment.getId();
			List<TeaEva> teaEvas = teaEvaDao.selectTeaEvaByCommentId(commentId);
			teaComment.setTeaEvas(teaEvas);
		}
		logger.info("TeaUserCommentServiceImpl getCommentListALl end");
		return BaseResult.success(teaComments);
	}

	
	public BaseResult getCommentListPart(String orderId) {
		logger.info("TeaUserCommentServiceImpl getCommentListPart start");
		List<TeaComment> teaComments = teaCommentDao.selectPartByOederId(orderId);
		logger.info("TeaUserCommentServiceImpl getCommentListPart end");
		return BaseResult.success(teaComments);
	}

}
